home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume17 / cproto / part01 next >
Encoding:
Internet Message Format  |  1991-03-25  |  11.7 KB

  1. From: cthuang@contact.UUCP (Chin Huang)
  2. Newsgroups: comp.sources.misc
  3. Subject: v17i070:  cproto - Generate C function prototypes from C source, Part01/02
  4. Message-ID: <1991Mar25.221120.22478@sparky.IMD.Sterling.COM>
  5. Date: 25 Mar 91 22:11:20 GMT
  6. Approved: kent@sparky.imd.sterling.com
  7. X-Checksum-Snefru: 6c4b15e3 4aee8f28 b50bbad9 590910f3
  8.  
  9. Submitted-by: Chin Huang <cthuang@contact.UUCP>
  10. Posting-number: Volume 17, Issue 70
  11. Archive-name: cproto/part01
  12.  
  13. Cproto is a program that generates function prototypes and variable
  14. declarations from C language source code.  It uses a yacc generated
  15. parser, so it isn't confused by complex function definitions as much
  16. as other prototype generators.  I avoided implementing the entire C
  17. language grammar by having the scanner discard everything between
  18. braces.
  19.  
  20. An earlier version of cproto appeared in comp.sources.unix.  This is
  21. an updated version with features added from Eric R. Smith's mkptypes
  22. program.
  23.  
  24. Chin
  25. --------
  26. #! /bin/sh
  27. # This is a shell archive.  Remove anything before this line, then unpack
  28. # it by saving it into a file and typing "sh file".  To overwrite existing
  29. # files, type "sh file -c".  You can also feed this as standard input via
  30. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  31. # will see the following message at the end:
  32. #        "End of shell archive."
  33. # Contents:  README CHANGES Makefile Makefile.uni cproto.1
  34. # Wrapped by ibmpc@laphroig.UUCP on Mon Mar 25 11:41:03 1991
  35. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  36. if test -f README -a "${1}" != "-c" ; then 
  37.   echo shar: Will not over-write existing file \"README\"
  38. else
  39. echo shar: Extracting \"README\" \(500 characters\)
  40. sed "s/^X//" >README <<'END_OF_README'
  41. XCproto is a program that generates function prototypes and variable
  42. Xdeclarations from C language source code.  It uses a yacc generated
  43. Xparser, so it isn't confused by complex function definitions as much
  44. Xas other prototype generators.  I avoided implementing the entire C
  45. Xlanguage grammar by having the scanner discard everything between
  46. Xbraces.
  47. X
  48. XCproto is in the public domain.  If you have any comments or find any
  49. Xbugs, please let me know.
  50. X
  51. XChin Huang
  52. Xcthuang@contact.uucp
  53. Xchin.huang@canrem.uucp
  54. END_OF_README
  55. if test 500 -ne `wc -c <README`; then
  56.     echo shar: \"README\" unpacked with wrong size!
  57. fi
  58. # end of overwriting check
  59. fi
  60. if test -f CHANGES -a "${1}" != "-c" ; then 
  61.   echo shar: Will not over-write existing file \"CHANGES\"
  62. else
  63. echo shar: Extracting \"CHANGES\" \(1575 characters\)
  64. sed "s/^X//" >CHANGES <<'END_OF_CHANGES'
  65. XVersion 2
  66. X
  67. X- Added formal parameter promotion.
  68. X- Added prototype style that surrounds prototypes with a guard macro.
  69. X- Handles C++ style comment //.
  70. X- Nifty new way to set prototype output format.
  71. X- Got rid of the shell wrapper used to pipe the input through the C
  72. X  preprocessor (cpp).
  73. X- For the port to MS-DOS, I modified cproto to run without cpp, but
  74. X  since I didn't want to reimplement cpp, the program processes only the
  75. X  #include and #define directives and ignores all others.  Macro names
  76. X  defined by the #define directive are treated like typedef names if
  77. X  they appear in declaration specifiers.
  78. X
  79. XVersion 1
  80. X
  81. XPatchlevel 3
  82. X
  83. X- Fix: identical typedef names and struct tags should be allowed.
  84. X  For example:
  85. X
  86. X    typedef struct egg_salad egg_salad;
  87. X
  88. X    struct egg_salad {
  89. X        int mayo;
  90. X    };
  91. X
  92. X    void dine(egg_salad l)
  93. X    {
  94. X    }
  95. X
  96. XPatchlevel 2
  97. X
  98. X- Fix: A typedef statement should allow a list of typedefs to be declared.
  99. X  Example:
  100. X
  101. X    typedef int a, *b;
  102. X
  103. X- Fix: When run with the -v option on this input, cproto did not output
  104. X  a declaration for variable "b":
  105. X
  106. X    char *a="one"; char *b="two";
  107. X
  108. X- The options were renamed.  Added new options that change the output
  109. X  format of the prototypes.
  110. X
  111. XPatchlevel 1
  112. X
  113. X- Fix: Incorrect prototypes were produced for functions that take
  114. X  function pointer parameters or return a function pointer.  For example,
  115. X  cproto produced an erroneous prototype for this function definition:
  116. X
  117. X    void
  118. X    (*signal (sig, func))()
  119. X    int sig;
  120. X    void (*func)();
  121. X    {
  122. X        /* stuff */
  123. X    }
  124. X
  125. X- The lexical analyser now uses LEX.  It should still be compatible with
  126. X  FLEX.
  127. END_OF_CHANGES
  128. if test 1575 -ne `wc -c <CHANGES`; then
  129.     echo shar: \"CHANGES\" unpacked with wrong size!
  130. fi
  131. # end of overwriting check
  132. fi
  133. if test -f Makefile -a "${1}" != "-c" ; then 
  134.   echo shar: Will not over-write existing file \"Makefile\"
  135. else
  136. echo shar: Extracting \"Makefile\" \(1405 characters\)
  137. sed "s/^X//" >Makefile <<'END_OF_Makefile'
  138. X# $Id: makefile 2.1 91/03/25 10:56:54 cthuang Exp $
  139. X#
  140. X# MSDOS makefile for C prototype generator
  141. X
  142. XLEX = lex
  143. XYACC = yacc
  144. XCC = tcc
  145. XCFLAGS = -ml -X $(DEFINES)
  146. X
  147. XDEFINES = -DMSDOS
  148. X
  149. XDIST1 =        README CHANGES Makefile Makefile.uni cproto.1
  150. XDIST2 =        $(SOURCES)
  151. XSOURCES =    lex.l grammar.y \
  152. X        config.h cproto.h patchlev.h semantic.h symbol.h \
  153. X        cproto.c semantic.c string.c symbol.c
  154. XCSOURCES =    cproto.c semantic.c string.c symbol.c y_tab.c
  155. XOBJECTS =    cproto.obj semantic.obj getopt.obj symbol.obj \
  156. X        y_tab.obj
  157. X
  158. Xall: cproto.exe
  159. X
  160. Xcproto.exe: $(OBJECTS)
  161. X    $(CC) $(CFLAGS) $(OBJECTS)
  162. X
  163. Xy_tab.obj: y_tab.c
  164. X    $(CC) $(CFLAGS) -c $*.c
  165. X
  166. Xy_tab.c: grammar.y
  167. X    $(YACC) grammar.y
  168. X
  169. Xlex_yy.c: lex.l
  170. X    $(LEX) lex.l
  171. X
  172. XTAGS: $(SOURCES)
  173. X    etags -t $(SOURCES)
  174. X
  175. Xclean:
  176. X    erase *.obj
  177. X    erase *.bak
  178. X    erase *.log
  179. X    erase lex_yy.c
  180. X    erase y_tab.c
  181. X    erase cproto1.exe
  182. X    
  183. Xlint:
  184. X    lint -B $(DEFINES) $(CSOURCES)
  185. X
  186. Xprint:
  187. X    cpr $(SOURCES) | lpr -J'cproto'
  188. X
  189. Xshar:
  190. X    rmcr $(DIST1)
  191. X    rmcr $(DIST2)
  192. X    shar $(DIST1) >cproto.sh1
  193. X    rmcr cproto.sh1
  194. X    shar $(DIST2) >cproto.sh2
  195. X    rmcr cproto.sh2
  196. X
  197. Xzip:
  198. X    pkzip -u cproto README CHANGES Makefile.* *.1 *.c *.h grammar.y lex.l
  199. X
  200. Xci:
  201. X    ci -r2 -u $(DIST1)
  202. X    ci -r2 -u $(DIST2)
  203. X
  204. X# DO NOT DELETE THIS LINE -- make depend depends on it.
  205. X
  206. Xcproto.obj: config.h cproto.h symbol.h
  207. Xsemantic.obj: config.h cproto.h symbol.h semantic.h
  208. Xstring.obj: config.h
  209. Xsymbol.obj: config.h symbol.h
  210. Xy_tab.obj: config.h cproto.h symbol.h semantic.h lex_yy.c
  211. END_OF_Makefile
  212. if test 1405 -ne `wc -c <Makefile`; then
  213.     echo shar: \"Makefile\" unpacked with wrong size!
  214. fi
  215. # end of overwriting check
  216. fi
  217. if test -f Makefile.uni -a "${1}" != "-c" ; then 
  218.   echo shar: Will not over-write existing file \"Makefile.uni\"
  219. else
  220. echo shar: Extracting \"Makefile.uni\" \(1195 characters\)
  221. sed "s/^X//" >Makefile.uni <<'END_OF_Makefile.uni'
  222. X# $Id: Makefile.uni 2.1 91/02/28 11:15:54 cthuang Exp $
  223. X#
  224. X# UNIX makefile for C prototype generator
  225. X
  226. XLEX = lex
  227. XYACC = yacc
  228. XCFLAGS = $(DEFINES)
  229. X
  230. X# Define SYSV for System V, otherwise BSD is assumed.
  231. X#DEFINES = -DSYSV
  232. X
  233. XDIST1 =        README CHANGES Makefile Makefile.dos cproto.1
  234. XDIST2 =        $(SOURCES)
  235. XSOURCES =    lex.l grammar.y \
  236. X        config.h cproto.h patchlev.h semantic.h symbol.h \
  237. X        cproto.c semantic.c string.c symbol.c
  238. XCSOURCES =    cproto.c semantic.c string.c symbol.c y.tab.c
  239. XOBJECTS =    cproto.o semantic.o string.o symbol.o y.tab.o
  240. X
  241. Xall: cproto
  242. X
  243. Xcproto: $(OBJECTS)
  244. X    $(CC) $(CFLAGS) -o $@ $(OBJECTS)
  245. X
  246. Xy.tab.c: grammar.y
  247. X    $(YACC) grammar.y
  248. X
  249. Xlex.yy.c: lex.l
  250. X    $(LEX) lex.l
  251. X
  252. XTAGS: $(SOURCES)
  253. X    etags -t $(SOURCES)
  254. X
  255. Xclean:
  256. X    rm *.o *.bak *.log cproto1.exe
  257. X    
  258. Xlint:
  259. X    lint -B $(DEFINES) $(CSOURCES)
  260. X
  261. Xprint:
  262. X    cpr $(SOURCES) | lpr -J'cproto'
  263. X
  264. Xshar:
  265. X    shar $(DIST1) >cproto.sh1
  266. X    shar $(DIST2) >cproto.sh2
  267. X
  268. Xci:
  269. X    ci -u $(DIST1) $(DIST2)
  270. X
  271. Xdepend:
  272. X    makedepend $(CSOURCES)
  273. X
  274. X# DO NOT DELETE THIS LINE -- make depend depends on it.
  275. X
  276. Xcproto.o: config.h cproto.h symbol.h
  277. Xsemantic.o: config.h cproto.h symbol.h semantic.h
  278. Xstring.o: config.h
  279. Xsymbol.o: config.h symbol.h
  280. Xy.tab.o: config.h cproto.h symbol.h semantic.h lex.yy.c
  281. END_OF_Makefile.uni
  282. if test 1195 -ne `wc -c <Makefile.uni`; then
  283.     echo shar: \"Makefile.uni\" unpacked with wrong size!
  284. fi
  285. # end of overwriting check
  286. fi
  287. if test -f cproto.1 -a "${1}" != "-c" ; then 
  288.   echo shar: Will not over-write existing file \"cproto.1\"
  289. else
  290. echo shar: Extracting \"cproto.1\" \(3271 characters\)
  291. sed "s/^X//" >cproto.1 <<'END_OF_cproto.1'
  292. X.\" $Id: cproto.1 2.1 91/03/25 10:13:30 cthuang Exp $
  293. X.\"
  294. X.de EX          \"Begin example
  295. X.ne 5
  296. X.if n .sp 1
  297. X.if t .sp .5
  298. X.nf
  299. X.in +.5i
  300. X..
  301. X.de EE        \"End example
  302. X.fi
  303. X.in -.5i
  304. X.if n .sp 1
  305. X.if t .sp .5
  306. X..
  307. X.TH CPROTO 1 "February 28, 1991"
  308. X.SH NAME
  309. Xcproto \- generate C function prototypes from C source code
  310. X.SH SYNOPSIS
  311. X.B cproto
  312. X[ 
  313. X.I option \fP...\fI
  314. X] [
  315. X.I file \fP...\fI
  316. X]
  317. X.SH DESCRIPTION
  318. X.B Cproto
  319. Xreads C source code files and outputs function prototypes for external
  320. Xfunctions defined in the source to standard output.
  321. XThe function definitions may be in the old style or ANSI style.
  322. XOptionally,
  323. X.B cproto
  324. Xalso outputs declarations for any external variables defined in the file.
  325. XIf no
  326. X.I file
  327. Xargument is given,
  328. X.B cproto
  329. Xtakes its input from the standard input.
  330. X.SH OPTIONS
  331. X.TP
  332. X.B \-e
  333. XOutput the keyword
  334. X.B extern
  335. Xin front of each declaration having global scope.
  336. X.TP
  337. X.BI \-f n
  338. XSet the style of function prototype where
  339. X.I n
  340. Xis a number from 0 to 4.
  341. XFor example, consider the function definition
  342. X.EX
  343. Xmain (argc, argv)
  344. Xint argc;
  345. Xchar *argv[];
  346. X{
  347. X ...
  348. X}
  349. X.EE
  350. XIf the value is 0, then no prototypes are generated.
  351. XWhen set to 1, the output is:
  352. X.EX
  353. Xint main(/*int argc, char *argv[]*/);
  354. X.EE
  355. XFor a value of 2, the output has the form:
  356. X.EX
  357. Xint main(int /*argc*/, char */*argv*/[]);
  358. X.EE
  359. XThe default value is 3.
  360. XIt produces the full function prototype:
  361. X.EX
  362. Xint main(int argc, char *argv[]);
  363. X.EE
  364. XA value of 4 produces prototypes guarded by a macro:
  365. X.EX
  366. Xint main P_((int argc, char *argv[]));
  367. X.EE
  368. X.TP
  369. X.BI \-m name
  370. XSet the name of the macro used to guard prototypes when option -f4 is selected.
  371. XBy default it is "P_".
  372. X.TP
  373. X.B \-d
  374. XOmit the definition of the prototype macro named by the -m option.
  375. X.TP
  376. X.B \-p
  377. XDisable promotion of formal parameters in function prototypes.
  378. XBy default, parameters of type
  379. X.B char
  380. Xor
  381. X.B short
  382. Xin traditional style function definitions are promoted to type
  383. X.B int
  384. Xin the function prototype.
  385. XParameters of type
  386. X.B float
  387. Xget promoted to 
  388. X.B double
  389. Xas well.
  390. X.TP
  391. X.B \-s
  392. XAlso output
  393. X.B static
  394. Xdeclarations.
  395. X.TP
  396. X.B \-v
  397. XAlso output declarations for variables defined in the file.
  398. X.TP
  399. X.BI \-F string
  400. XSet the format used to output each prototype.
  401. XThe string is a template in the form
  402. X.EX
  403. X" int main ( a, b )"
  404. X.EE
  405. Xwhere each space in the string may be replaced with whitespace characters.
  406. XFor example, the option
  407. X.EX
  408. X-F"int main(\\n\\ta,\\n\\tb\\n\\t)"
  409. X.EE
  410. Xwill produce prototypes in the format
  411. X.EX
  412. Xint main(
  413. X        int argc,
  414. X        char *argv[]
  415. X        );
  416. X.EE
  417. X.TP
  418. X.BI \-D name\[=value\]
  419. XThis option is passed through to the preprocessor and is used to define 
  420. Xsymbols for use with conditionals such as
  421. X.I #ifdef.
  422. X.TP
  423. X.BI \-U name
  424. XThis option is passed through to the preprocessor and is used to remove
  425. Xany definitions of this symbol.
  426. X.TP
  427. X.BI \-I directory
  428. XThis option is passed through to the preprocessor and is used to specify
  429. Xa directory to search for files that are referenced with 
  430. X.I #include.
  431. X.TP
  432. X.B \-V
  433. XPrint version information.
  434. X.SH AUTHOR
  435. XChin Huang
  436. Xcthuang@contact.uucp
  437. Xchin.huang@canrem.uucp
  438. X.SH BUGS
  439. XWhen cproto finds an error, it usually outputs the not very descriptive
  440. Xmessage "syntax error".
  441. X.TP
  442. XOptions that take string arguments only interpret the following
  443. Xcharacter escape sequences:
  444. X.EX
  445. X\\n    newline
  446. X\\t    tab
  447. X.EE
  448. X.SH "SEE ALSO"
  449. Xcc(1),
  450. Xcpp(1)
  451. END_OF_cproto.1
  452. if test 3271 -ne `wc -c <cproto.1`; then
  453.     echo shar: \"cproto.1\" unpacked with wrong size!
  454. fi
  455. # end of overwriting check
  456. fi
  457. echo shar: End of shell archive.
  458. exit 0
  459. -- 
  460. Chin Huang  cthuang@contact.uucp  chin.huang@canrem.uucp
  461.  
  462. exit 0 # Just in case...
  463. -- 
  464. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  465. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  466. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  467. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  468.